/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ma.projet.managedBean;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import ma.projet.facade.PersonneFacadeLocal;
import ma.projet.model.Personne;

/**
 *
 * @author Mariama
 */
public class AuthentificationBean {

     @EJB
    PersonneFacadeLocal fpersonne;
    Personne personne;
    boolean islogged;

    public boolean isIslogged() {
        return islogged;
    }

    public void setIslogged(boolean islogged) {
        this.islogged = islogged;
    }
    
    /**
     * Creates a new instance of AuthentificationBean
     */
    public AuthentificationBean() {
        personne=new Personne();
        islogged=false;
       
    }

    public Personne getPersonne() {
        return personne;
    }

    public void setPersonne(Personne personne) {
        this.personne = personne;
    }
    public String login()
    {
        FacesContext context = FacesContext.getCurrentInstance(); 
        personne = fpersonne.login(personne);
        if(personne!=null){
           islogged=true;
            return "index";
        }
        else 
        {
           
         context.addMessage(null, new FacesMessage("Erreur Authentification"));
          FacesContext.getCurrentInstance().getExternalContext().getSessionMap().clear();
          return null;
        }
    }
}
